home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-17 | 9.9 KB | 293 lines | [TEXT/MPS ] |
- /*
- * This file has been changed from the original MacApp 3.1.1
- * to support the metrowerks CodeWarrior compilers C/C++ 1.1.1.
- * These changes are known *not* to work with earlier versions
- * of CodeWarrior. Every attempt though has been made to to keep
- * this file compatible with other development environments.
- *
- * Mark Anderson
- * metrowerks
- * 9/16/94
- *
- */
-
- // UObject.h
- // Copyright 1984-1994 Apple Computer, Inc. All rights reserved.
-
- #ifndef __UOBJECT__
- #define __UOBJECT__
-
- #ifndef __MACAPPTYPES__
- #include <MacAppTypes.h>
- #endif
-
- #ifndef __UPOINTEROBJECT__
- #include <UPointerObject.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TObject;
- class TStream;
- class TDependencySpace;
-
- //----------------------------------------------------------------------------------------
- // Typedefs
- //----------------------------------------------------------------------------------------
-
- enum ComparisonResult
- {
- kLessThan = -1,
- kEqual = 0,
- kGreaterThan = 1
- };
-
- typedef long HashValue;
-
- //----------------------------------------------------------------------------------------
- // TObject: Definition of the system's root object
- //----------------------------------------------------------------------------------------
-
- DeclareClassDesc(TObject);
-
- // ••• JS NEW ••• singleobject + forceclassidfirst + classdescmany
-
- #if qMultipleInheritance || qPowerPC || defined(__MWERKS__) || defined(THINK_C) || defined(__SC__)
- #if (qDebug || qSym) && defined(__MWERKS__)
- // make sure CodeWarrior puts fClassID first, not the vtable
- struct ForceClassIDFirst
- {
- ClassID fClassID;
- };
- class TObject : public ForceClassIDFirst
- #else
- // assume the other compilers already put fClassID first (for Jasik)
- class TObject
- #endif
- #else
- // for MPW C only and no MI, descend from SingleObject, so vtables are smaller
- class TObject : public SingleObject
- #endif
- {
- DeclareClass(TObject);
-
- public:
-
- #if (qDebug || qSym) && !defined(__MWERKS__)
- ClassID fClassID; // Used to do object validation in debug mode.
- #endif
-
- //------------------------------------------------------------------------------------
- // Initializer and I<Method>.
- //------------------------------------------------------------------------------------
-
- TObject();
- // Constructor
-
- #if qClassDescMany || (qDebug && THINK_CPLUS)
- virtual ~TObject() {}
- // Virtual Destructor
- #endif
-
- void IObject();
- // The ancestral initializer. Should be called in the I<ClassName> chain. i.e.
- // IView -> IEventHandler -> IObject, followed by a called to <ClassName> i.e without
- // the T.
-
- //------------------------------------------------------------------------------------
- // Comparison
- //------------------------------------------------------------------------------------
-
- HashValue Hash() const;
-
- virtual Boolean IsSame(const TObject* theObject) const;
- // Does a handle comparison to determine if the objects are in fact the same object
-
- virtual Boolean IsEqual(const TObject* theObject) const;
- // Must be overridden to be useful. Default implementation calls IsSame
-
- virtual ComparisonResult CompareObject(const TObject* theObject) const;
- // Compares two objects.
-
- virtual Boolean IsGreaterThan(const TObject* obj) const;
-
- virtual Boolean IsLessThan(const TObject* obj) const;
-
- Boolean operator<(const TObject& obj) const;
- // Calls back to IsLessThan.
-
- Boolean operator>(const TObject& obj) const;
- // Calls back to IsGreaterThan.
-
- Boolean operator>=(const TObject& obj) const;
- // Calls back to IsGreaterThan and IsEqual.
-
- Boolean operator<=(const TObject& obj) const;
- // Calls back to IsLessThan and IsEqual.
-
- Boolean operator ==(const TObject& obj) const;
- // Calls back to IsEqual.
-
- Boolean operator !=(const TObject& obj) const;
-
- //------------------------------------------------------------------------------------
- // Change notification
- //------------------------------------------------------------------------------------
-
- void AddDependent(TObject* dependent);
- // Registers the specified object as a dependent of this object in the global
- // dependency space "gMacAppDependencies", so that it will be notified of changes
- // in this object.
-
- void RemoveDependent(TObject* dependent);
- // Remove the specified object from the list of dependents of this object in
- // the global dependency space "gMacAppDependencies".
-
- virtual void Changed(ChangeID theChange, TObject* changedBy);
- // Called to inform dependents of this object in the global dependency space
- // "gMacAppDependencies" that it has been changed.
- // "theChange" will often contain a command number.
- // "changedBy" will often contain a command object.
- // Called often, overridden rarely.
-
- virtual void DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace);
- // Informs this object that an object on which it is dependent in the global
- // dependency space "gMacAppDependencies" has been changed.
- // Called rarely, overridden often.
-
- virtual TDependencySpace* GetDependencySpace();
- // Returns the default dependency space for storing dependents of this object.
- // Returns gMacAppDependencies.
-
- virtual void SetMark(Boolean state);
- // Intended to mark (state=true) or unmark (state=false) this object. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual Boolean IsMarked();
- // Intended to return true if this object is marked. Can be used
- // by dependency spaces that require marking, and overridden by objects that store the
- // mark internally. The MacApp dependency spaces do not use this method.
-
- virtual void RemoveAllDependencies();
- // Used by TObject::Free to remove all dependency relations in the global
- // dependency space "gMacAppDependencies" which involve this object, either
- // as notifier or as dependent.
-
- virtual Boolean RemoveDependenciesOnFree();
- // Default is to return true. This will allow us to optimize certain system
- // objects (like TToolBoxEvents).
-
-
-
- //------------------------------------------------------------------------------------
- // Standard signature support.
- //------------------------------------------------------------------------------------
-
- virtual IDType GetStandardSignature(); // override
- // Returns this class's standard signature.
-
- //------------------------------------------------------------------------------------
- // Stream I/O protocol support.
- //------------------------------------------------------------------------------------
-
- virtual void ReadFrom(TStream* aStream);
-
- virtual void WriteTo(TStream* aStream);
-
-
- //------------------------------------------------------------------------------------
- // Miscellaneous protocol and support methods.
- //------------------------------------------------------------------------------------
-
- virtual TObject* Clone();
- // Makes a duplicate copy of this. The default calls this->ShallowClone, which
- // makes a literal copy of instance variables but does not attempt to clone owned
- // objects. A subclass which owns other objects should override this to clone the
- // owned objects and data structures as well.
-
- virtual void Free();
- // Called to dispose of an object. Gives object a chance to cleanup after itself.
- // Default simply calls this->ShallowFree, which makes no attempt to free instance
- // variables. Should be overridden by any class which allocates space or owns
- // other objects in its instance variables.. Be sure to call Inherited!
-
- ClassID GetClassID();
- // Returns the class ID of this.
-
- void GetClassName(ClassName& clName);
- // Returns the class name of this.
-
- size_t GetClassSize();
- // Returns the basic instantiation size. i.e. the size in bytes of a newly created
- // object of this class.
-
- const ClassDesc* GetSuperClass();
- // Returns ClassDesc for the immediate superclass. Returns NULL for TObject. If we
- // ever get MI this will have to be an enumerator.
-
- Boolean DescendsFrom(const ClassDesc* classDesc);
- // True if my class is a subclass of the class described by ClassDesc.
-
- Boolean IsSameClass(const ClassDesc* classDesc);
- // True if my class is the same as the class described by ClassDesc.
-
- virtual TObject* ShallowClone();
- // Lowest level method for copying an object; should not be overridden except in
- // very unusual cases. Simply calls HandToHand to copy the object data.
-
- virtual void ShallowFree();
- // Lowest level method for freeing an object; should not be overridden except in
- // very unusual cases. Simply calls delete to free the object.
-
- void SubClassResponsibility();
- // Called from methods that MUST be overridden in a subclass. Signals failure.
- };
-
-
- typedef TObject* TObjectPtr;
-
- typedef TObjectPtr* TObjectPtrPtr;
-
- typedef TObjectPtrPtr* TObjectPtrHandle;
-
-
- //----------------------------------------------------------------------------------------
- // INLINES TObject
- //----------------------------------------------------------------------------------------
-
- inline Boolean TObject::operator==(const TObject& obj) const
- {
- return (this->IsEqual(&obj));
- }
-
- inline Boolean TObject::operator!=(const TObject& obj) const
- {
- return (this->IsEqual(&obj) == false);
- }
-
- inline Boolean TObject::operator<(const TObject& obj) const
- {
- return (this->IsLessThan(&obj));
- }
- inline Boolean TObject::operator>(const TObject& obj) const
- {
- return (this->IsGreaterThan(&obj));
- }
- inline Boolean TObject::operator>=(const TObject& obj) const
- {
- return (this->IsGreaterThan(&obj) || this->IsEqual(&obj));
- }
- inline Boolean TObject::operator<=(const TObject& obj) const
- {
- return (this->IsLessThan(&obj) || this->IsEqual(&obj));
- }
-
- #endif
-